package edu.jd.movieplatform.security.admin;

import edu.jd.movieplatform.common.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController //说明这是一个受spring容器管理的控制器组件(Bean)
@RequestMapping("/security/admin") //本控制器的路径前缀
public class AdminAPI {
    //引入依赖对象
    @Resource //此注解表示从容器中引入依赖对象
    private AdminService adminService;

    @GetMapping("")
    public Result queryAdmins(AdminDto dto){
        Map<String,Object> page =  adminService.getAdminPage(dto);
        return Result.success(page);
    }

    @GetMapping("/{m_id}")
    public Result queryAdminById(@PathVariable String m_id){
        Admin admin =  adminService.getAdminById(m_id);
        return Result.success(admin);
    }

    @PostMapping("")
    public Result addAdmin(@RequestBody AdminDto dto){
        adminService.addAdmin(dto);
        return Result.success();
    }

    @PutMapping("")
    public Result updateAdmin(@RequestBody AdminDto dto){
        adminService.updateAdmin(dto);
        return Result.success();
    }

    /**
     * 按照账号删除一个用户信息
     * @param m_id,m_status
     * @return
     */
    @DeleteMapping("/{m_id}")
    public Result deleteAdmin(@PathVariable String m_id){
        adminService.deleteOneAdmin(m_id);
        return Result.success();
    }

    /**
     * 根据多个账号删除多个用户信息
     * @param
     * @return
     */
    @DeleteMapping("/del")
    public Result deleteAdmin(@RequestBody DelAdminDto[] delAdmin){
        adminService.deleteAdmin(delAdmin);
        return Result.success();
    }

}
